#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void Test1()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    sort(v.begin(), v.end());

    int head, tail;
    for (head = 0, tail = 0; tail < n; tail++)
    {
        if (v[tail] - v[head] > k) head++;
    }

    cout << tail - head << endl;

}


typedef long long ll;

bool is_prime(ll c)
{
    if (c < 2)
    {
        return false;
    }

    for (int i = 2; i * i <= c; i++)
    {
        if (c % i == 0) return false;
    }

    return true;
}

int main() {

    int n;
    cin >> n;

    ll x, y;
    while (n--)
    {
        cin >> x >> y;
        if (x == 1 && is_prime(y) || y == 1 && is_prime(x))
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}